class Solution {
    public int mySqrt(int x) {
        if(x < 1){
            return 0;
        }
        int left = 1, rihgt = x;
        while(left < rihgt){
            long mid = left + (rihgt - left + 1) / 2;
            long t = mid * mid;
            if(t <= x){
                left = (int)mid;
            }else{
                rihgt = (int)mid - 1;
            }
        }
        return left;
    }
}